package cn.itcast.web.controller.cargo;

import cn.itcast.domain.cargo.ContractExample;
import cn.itcast.domain.cargo.ExportExample;
import cn.itcast.service.cargo.ContractService;
import cn.itcast.service.cargo.ExportService;
import cn.itcast.web.controller.BaseController;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/cargo/export")
public class ExportController extends BaseController {

    @Reference
    private ExportService exportService;

    @Reference
    private ContractService contractService;

    /*
        分页查询所有合同单据
        地址：/cargo/export/contractList.do
     */
    @RequestMapping("/contractList")
    public String contractList(
            @RequestParam(defaultValue = "1")int page,
            @RequestParam(defaultValue = "5")int size){
        //设置查询条件（查询状态为1  企业为当前登录企业的报运单数据
        ContractExample example = new ContractExample();
        ContractExample.Criteria criteria = example.createCriteria();
        criteria.andCompanyIdEqualTo(getLoginCompanyId());//设置查询当前登录企业数据
        criteria.andStateEqualTo(1);//设置查询状态为1的数据
        example.setOrderByClause("create_time DESC");//设置排序
        //调用exportService查询
        PageInfo info = contractService.findAll(page, size, example);
        //将数据保存到request域中
        request.setAttribute("page",info);
        return "cargo/export/export-contractList";
    }
}
